﻿using AutoMapper;
using DDD.Application;
using DDD.Domain;
using DotNetCore.CAP;
using GoodsModule.IntegrationEvents;
using MediatR;
using Microsoft.Extensions.Logging;
using OrderModule.IntegrationEvents;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GoodsModule.Application.IntegrationEventsHandler
{
    internal class OrderCreatedIntegrationEventHandler(IMediator mediator)
        : IIntegrationEventHandler
    {
        [CapSubscribe(nameof(OrderCreatedIntegrationEvent))]
        public Task Handle(OrderCreatedIntegrationEvent @event, CancellationToken cancellationToken = default)
        {
            var cmd = new Commands.DeductGoodsStockByOrderCommand()
            {
                OrderId = @event.OrderId,
                GoodsId_Quantity = @event.GoodsId_Quantity,
            };
            return mediator.Send(cmd, cancellationToken);
        }
    }
}
